#pragma once
#include <string>
#include <stdio.h>
#include <stdlib.h>
#include <sys/uio.h>
#include <string.h>
#include <unistd.h>
#include <strings.h>
#include <sys/socket.h>
#include <iostream>
using namespace std;

class Buffer
{
public:
    Buffer(int size);
    ~Buffer();
    void extendRoom(int size);
    int appendString(const char* data, int size);
    int appendString(const char* data);
    int appendString(const string data);
    int socketRead(int fd);
    char* findCRLF();
    int sendData(int fd);
    inline int writeableSize()
    {
        return m_capacity - m_writePos;
    }
    inline int readableSize()
    {
        return m_writePos - m_readPos;
    }
    inline char* data_pos()
    {
        return m_data + m_readPos;
    }
    inline int readPosIncrease(int count)
    {
        m_readPos += count;
        return m_readPos;
    }
private:
    char* m_data;
    int m_capacity;
    int m_readPos = 0;
    int m_writePos = 0;
};

